namespace DiLu.Expansion.File.Configs;

/// <summary>
///     获取文件配置
/// </summary>
public abstract record DeleteFileConfig
{
    /// <summary>
    ///     获取文件流配置
    /// </summary>
    /// <param name="fileFullPath">文件完整路径</param>
    protected DeleteFileConfig(string fileFullPath)
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(fileFullPath, nameof(fileFullPath));
        fileFullPath = fileFullPath.Replace('\\', '/').Trim();
        var rootPath = Path.GetPathRoot(fileFullPath);
        ArgumentException.ThrowIfNullOrWhiteSpace(rootPath, nameof(rootPath));
        if (new DriveInfo(rootPath).DriveType == DriveType.Unknown) throw new ArgumentException("目录与系统目录不匹配");

        FileFullPath = fileFullPath.Trim();
    }

    /// <summary>
    ///     获取文件流配置
    /// </summary>
    /// <param name="rootDirectory">根目录</param>
    /// <param name="fileGroupName">文件分组名称</param>
    /// <param name="fileRelativePath">文件相对路径</param>
    protected DeleteFileConfig(string rootDirectory, string fileGroupName, string fileRelativePath)
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(rootDirectory, nameof(rootDirectory));
        rootDirectory = rootDirectory.Replace('\\', '/').Trim();
        var rootPath = Path.GetPathRoot(rootDirectory);
        ArgumentException.ThrowIfNullOrWhiteSpace(rootPath, nameof(rootPath));
        if (new DriveInfo(rootPath).DriveType == DriveType.Unknown) throw new ArgumentException("目录与系统目录不匹配");
        ArgumentException.ThrowIfNullOrWhiteSpace(fileRelativePath, nameof(fileRelativePath));

        RootDirectory = rootDirectory;
        FileGroupName = $"{fileGroupName?.Trim()}";
        FileRelativePath = fileRelativePath.Trim();
        FileFullPath = Path.Combine(RootDirectory, FileGroupName, FileRelativePath);
    }

    /// <summary>
    ///     根目录
    /// </summary>
    public string RootDirectory { get; }

    /// <summary>
    ///     文件分组名称
    /// </summary>
    public string FileGroupName { get; }

    /// <summary>
    ///     文件相对路径
    /// </summary>
    public string FileRelativePath { get; }

    /// <summary>
    ///     文件完整路径
    /// </summary>
    public string FileFullPath { get; }
}